package kr.blogspot.stiner01.moduletutorial;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class BitmapTest extends Activity
{
	class RenderView extends View
	{
		Bitmap _bob565;
		Bitmap _bob4444;
		
		Rect _dst = new Rect();

		public RenderView(Context context)
		{
			super(context);
			
			try
			{
				AssetManager assetManager = context.getAssets();
				InputStream inputStream = null;
				
				inputStream = assetManager.open("bobrgb888.png");
				_bob565 = BitmapFactory.decodeStream(inputStream);
				inputStream.close();
				Log.d("BitmapText", "bobrgb888.png format: " + _bob565.getConfig());
				
				inputStream = assetManager.open("bobargb8888.png");
				BitmapFactory.Options options = new BitmapFactory.Options();
				options.inPreferredConfig = Bitmap.Config.ARGB_4444;
				_bob4444 = BitmapFactory.decodeStream(inputStream, null, options);
				inputStream.close();
				Log.d("BitmapText", "bobargb8888.png format: " + _bob4444.getConfig());
			}
			catch (IOException e)
			{
			}
			finally
			{
			}
		}
		
		@Override
		protected void onDraw(Canvas canvas)
		{
			super.onDraw(canvas);
			
			_dst.set(50, 50, 350, 350);
			canvas.drawBitmap(_bob565, null, _dst, null);
			canvas.drawBitmap(_bob4444, 100, 100, null);
			
			invalidate();
		}
		
		public void Release()
		{
			_bob565.recycle();
			_bob4444.recycle();
			
			Log.d("BitmapText", "recycled bitmaps");
		}
	}
	
	private RenderView _view;
	
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        _view = new RenderView(this);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(_view);
    }
    
    @Override
    protected void onPause()
    {
    	super.onPause();
    	
    	if (isFinishing())
    	{
    		_view.Release();
    	}
    }
}
